<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const p = new Promise((resolve, reject) => {
            //resolve();
            reject();

        });

        p.then(
            () => {
                console.log('success');
            },
            () => {
                console.log('err');
                return 123;
                //在then的回调函数中，return后面的东西，会用Promise包装一下
                //return undefined
                //等价于
                //return  new Promise((resolve, reject) => {
                //resolve(undefined);
                //})
                //默认返回的永远都是成功状态的Promise对象
                //return new Promise((resolve, reject) => {
                //    reject('reason')
                //});

            }).then(
            (data) => {
                console.log('success2', data);
                //  return undefined;等价于
                return new Promise((resolve, reject) => {
                    resolve(undefined);
                })
            },
            () => {
                console.log('err2');
            }
        ).then(
            (data) => {
                console.log('success3', data);
            }, (err) => {
                console.log('err3', err);
            })



        //then什么时候执行
        //pending->fulfilled时，执行then的第一个回调函数
        //pending->resolved时，执行then的第二个回调函数

        //执行后的返回的值： 返回一个新的Promise对象
    </script>
</body>

</html>